package com.sc.admin.service;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.sc.admin.common.MysqlQuery;
import com.sc.admin.mapper.UserMapper;
import com.sc.admin.pojo.User;
import com.sc.admin.utils.MD5Utils;

@Service
public class UserServiceImpl implements UserService {
	@Autowired
	private UserMapper userMapper;
	
	@Override
	public int getCount() {
		return userMapper.selectCount();
	}

	@Override
	public List<User> getUsers(int page, int rows) {
		return userMapper.selectUsers(new MysqlQuery(page, rows));
	}

	@Override
	public void add(User user) {
		//对密码进行加密,默认密码是“111111”
		user.setPassword(MD5Utils.encode("111111"));
		userMapper.insertSelective(user);
	}

	@Override
	public User checkUser(User user) {
		return userMapper.selectUserByUser(user);
	}

	@Override
	public void update(User user) {
		userMapper.updateByPrimaryKeySelective(user);
	}

	@Override
	public List<User> getUsers(int page, int rows, User user) {
		return userMapper.selectUsers(new MysqlQuery<User>(page, rows,user));
	}

}
